package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.groupfifteen.entity.SysDictEntity;
import com.groupfifteen.entity.SysDictTypeEntity;
import com.groupfifteen.entity.SysUserEntity;
import com.groupfifteen.service.SysDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.groupfifteen.service.SysDictService;

import java.util.Map;
@Slf4j
@RestController
@RequestMapping("backend/dict")
public class SysDictController {

    @Autowired
    private SysDictService sysDictService;
    @PostMapping("/list")
    public IPage list(@RequestBody Map<String, Object> params) {
        IPage<SysDictEntity> page = sysDictService.queryPage(params);
        return page;
    }
    @PostMapping("adddict")
    public String AddDict(@RequestBody SysDictEntity sysDictEntity) {
        Integer result = sysDictService.AddDict(sysDictEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    //
    @DeleteMapping("/deletedict/{dict_code}")
    public String DeleteDict(@PathVariable("dict_code") Integer dict_code) {
        Integer result = sysDictService.DeleteDict(dict_code);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/getdict/{dict_code}")
    public SysDictEntity GetDict(@PathVariable("dict_code") Integer dict_code) {
        SysDictEntity result = sysDictService.GetDict(dict_code);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    @PutMapping("/updatedict/{dict_code}")
    public String UpdateDict(@PathVariable("dict_code")long dict_code,@RequestBody SysDictEntity sysDictEntity) {
        sysDictEntity.setDictCode(dict_code);
        Integer result = sysDictService.UpdateDict(sysDictEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
}
